#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,n,ans,a[100005],dp[100005][2];
void work(ll dep,ll red,ll blue,ll score){
    if(dep>n){
        ans=max(ans,score);
        return;
    }
    work(dep+1,dep,blue,score+a[dep]*(a[dep]==a[red]));
    work(dep+1,red,dep,score+a[dep]*(a[dep]==a[blue]));
}
void solve(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    ans=0;work(0,0,0,0);
    printf("%lld\n",ans);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    for(ll i=1;i<=T;i++)solve();
    return 0;
}
